"""
@Author: 霍格沃兹测试开发学社-西西
@Desc: 更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860
"""

class Student:
    def __init__(self, name, scores):
        '''
        构造方法
        实例化一个对象
        '''
        self.name = name
        self.scores = scores

    def __str__(self):
        '''
        打印对象的时候，可以将对象转成 字符串
        :return:
        '''
        return f"{self.name}: {self.scores}"

    def coding(self):
        print(f"{self.name} 正在编码")

    def playing(self):
        print(f"{self.name} 正在打游戏")

"""
面向对象 
属性，方法
属性：学员列表
方法：新增、移除、获取学员信息、得到所有学员的平均成绩
"""

class StudentManager:
    def __init__(self):
        self.students = []

    def add_student(self, student):
        print("准备新增一个新的学员")
        self.students.append(student)
        print(f"新增完毕，新增的学员姓名为：{student.name}")

    def remove_student(self, name):
        '''
        移除学员
        :param name: 被移除学员的名字
        :return:
        '''
        for student in self.students:
            if student.name == name:
                self.students.remove(student)
                break

    def get_student_info(self, name):
        '''
        获取学员的信息
        :param name:
        :return:
        '''
        # 方法没有return  返回None
        # 有一个return 遇到return 返回
        # 有多个return 看逻辑
        for student in self.students:
            if student.name == name:
                return str(student)
        return "No such student found"

    def average_score(self):
        total = 0
        for student in self.students:
            total += student.scores
        return total / len(self.students)

student_manager = StudentManager()

# 添加学生
student1 = Student("Alice", 90)
student2 = Student("Bob", 85)
student_manager.add_student(student1)
student_manager.add_student(student2)

# 查询学生信息
print(student_manager.get_student_info("Alice"))
print(student_manager.get_student_info("Bob"))

# 计算平均分数
print(student_manager.average_score())

# 删除学生
student_manager.remove_student("Alice")
print(student_manager.get_student_info("Alice"))
